$('document').ready(function(){
    //波高
	$("#waveheight").combobox({
        url: 'pose/waveTrans.do',
        method : "get",
        valueField: 'transducerNumber',
        textField: 'transducerName',
        selected: 'selected',
        multiple: false
	});
	
	$("#currentspeed").combobox({
        url: 'pose/currentSpeedTrans.do',
        method : "get",
        valueField: 'transducerNumber',
        textField: 'transducerName',
        selected: 'selected',
        multiple: false
	});

	$("#accelration").combobox({
        url: 'pose/accTrans.do',
        method : "get",
        valueField: 'transducerNumber',
        textField: 'transducerName',
        selected: 'selected',
        multiple: false
	});
});

var startFlg=false;
var interval3=setInterval(function(){
	if (startFlg) {
		$('#submit').click();
	}

},2000);


$('#submit').click(function(){
	startFlg=true;
	var options={
		    fontFamily: 'Roboto',
			name: '波高',
		    //backgroundColor: '#C6E2FF',
		    backgroundColor: '#FFFFFF',
		    title: {
		        text: '波浪/流速', 
		        textStyle: {
		            fontWeight: 'bolder',
		            fontSize: 18,
		            color: 'black',
		        },
		        right: '0%',
		        top: '0%'
		    },
		   

		    grid: {
		        left: '1%',
		        right: '5%',
		        bottom: '0%',
		        containLabel: true
		    },
		    xAxis: [{
		        type: 'category',
		        boundaryGap: false,
		        data: ["0", "5", "10", "15", "20", "25","30","35","40","45"],
		        axisLabel: {
		            show: true,
		            interval: 0,
		            fontSize: 20,
		            color: '#ffffff',
		            fontWeight: 'bold',

		            formatter:'{value} 秒'
		        },
		        axisLine: {
		            show: true
		        },
		        axisTick: {
		            show: true
		        },
		    }],
		    yAxis: [{
		        show: true,
		        max: 5, 
		    }],
		    series: [{
		        name: '振幅',
		        type: 'line',
		        smooth: true,
		        symbol: 'circle',
		        showSymbol: true,
		        lineStyle: {
		            normal: {
		                color: '#79CDCD',
		                width: 3,
		                //type: 'dashed'
		            }
		        },
		         
		        label: {
		            normal: {
		                show: true,
		                position: 'top',
		                color: '#fff',
		                fontSize: 24,
		            },
		        },
		        markLine: {
		            
		            lineStyle: {
		                normal: {
		                	color: 'red',
		                },
		            },
		            data: [{
		                name: '',
		                label: {
		                    normal: {
		                        formatter: '',
		                        position: 'middle',
		                        fontSize: 18,
		                    }
		                },
		                yAxis: 2, 
		            }]
		        },
		        data: [3, 1, 3, 1, 3, 1, 3, 1, 3, 1]
		    }]
        };
	var options1={
		    fontFamily: 'Roboto',
			name: '流速',
		    //backgroundColor: '#C6E2FF',
		    backgroundColor: '#FFFFFF',
		    title: {
		        text: '波浪/流速', 
		        textStyle: {
		            fontWeight: 'bolder',
		            fontSize: 18,
		            color: 'black',
		        },
		        right: '0%',
		        top: '0%'
		    },
		   

		    grid: {
		        left: '1%',
		        right: '5%',
		        bottom: '0%',
		        containLabel: true
		    },
		    xAxis: [{
		        type: 'category',
		        boundaryGap: false,
		        data: ["0", "5", "10", "15", "20", "25","30","35","40","45"],
		        axisLabel: {
		            show: true,
		            interval: 0,
		            fontSize: 20,
		            color: '#ffffff',
		            fontWeight: 'bold',

		            formatter:'{value} 秒'
		        },
		        axisLine: {
		            show: true
		        },
		        axisTick: {
		            show: true
		        },
		    }],
		    yAxis: [{
		        show: true,
		        max: 5, 
		    }],
		    series: [{
		        name: '振幅',
		        type: 'line',
		        smooth: true,
		        symbol: 'circle',
		        showSymbol: true,
		        lineStyle: {
		            normal: {
		                color: '#79CDCD',
		                width: 3,
		                //type: 'dashed'
		            }
		        },
		         
		        label: {
		            normal: {
		                show: true,
		                position: 'top',
		                color: '#fff',
		                fontSize: 24,
		            },
		        },
		        markLine: {
		            
		            lineStyle: {
		                normal: {
		                	color: 'red',
		                },
		            },
		            data: [{
		                name: '',
		                label: {
		                    normal: {
		                        formatter: '',
		                        position: 'middle',
		                        fontSize: 18,
		                    }
		                },
		                yAxis: 2, 
		            }]
		        },
		        data: [3, 1, 3, 1, 3, 1, 3, 1, 3, 1]
		    }]
        };
	var options2={
		    fontFamily: 'Roboto',
			name: '水平位移',
		    //backgroundColor: '#C6E2FF',
		    backgroundColor: '#FFFFFF',
		    title: {
		        text: '水平位移', 
		        textStyle: {
		            fontWeight: 'bolder',
		            fontSize: 18,
		            color: 'black',
		        },
		        right: '0%',
		        top: '0%'
		    },
		   

		    grid: {
		        left: '1%',
		        right: '5%',
		        bottom: '0%',
		        containLabel: true
		    },
		    xAxis: [{
		        type: 'category',
		        boundaryGap: false,
		        data: ["0", "5", "10", "15", "20", "25","30","35"],
		        axisLabel: {
		            show: true,
		            interval: 0,
		            fontSize: 20,
		            color: '#ffffff',
		            fontWeight: 'bold',

		            formatter:'{value}'
		        },
		        axisLine: {
		            show: true
		        },
		        axisTick: {
		            show: true
		        },
		    }],
		    yAxis: [{
		        show: true,
		    }],
		    series: [{
		        name: '振幅',
		        type: 'line',
		        smooth: true,
		        symbol: 'circle',
		        showSymbol: true,
		        lineStyle: {
		            normal: {
		                color: '#79CDCD',
		                width: 3,
		                //type: 'dashed'
		            }
		        },
		         
		        label: {
		            normal: {
		                show: true,
		                position: 'top',
		                color: '#fff',
		                fontSize: 24,
		            },
		        },
		        data: [0,0.5,1,1.5,2,1.5,1,0]
		    }]
        };
	option3 = {
		    title : {
		        text: '加速度',
		        subtext: '随机数'
		    },
		    tooltip : {
		        trigger: 'axis'
		    },
		    legend: {
		        data:['加速度1','加速度2']
		    },
		    
		    calculable : true,
		    xAxis : [
		        {
		            type : 'category',
		            data : ['1','2','3','4','5','6','7','8']
		        }
		    ],
		    yAxis : [
		        {
		            type : 'value'
		        }
		    ],
		    series : [
		        {
		            name:'蒸发量',
		            type:'bar',
		            data:[2.0, 4.9, 7.0, 23.2, 25.6, 76.7, 135.6, 162.2, 32.6, 20.0, 6.4, 3.3],
		            markPoint : {
		                data : [
		                    {type : 'max', name: '最大值'},
		                    {type : 'min', name: '最小值'}
		                ]
		            },
		            markLine : {
		                data : [
		                    {type : 'average', name: '平均值'}
		                ]
		            }
		        },
		        {
		            name:'降水量',
		            type:'bar',
		            data:[2.6, 5.9, 9.0, 26.4, 28.7, 70.7, 175.6, 182.2, 48.7, 18.8, 6.0, 2.3],
		            markPoint : {
		                data : [
		                    {name : '年最高', value : 182.2, xAxis: 7, yAxis: 183, symbolSize:18},
		                    {name : '年最低', value : 2.3, xAxis: 11, yAxis: 3}
		                ]
		            },
		            markLine : {
		                data : [
		                    {type : 'average', name : '平均值'}
		                ]
		            }
		        }
		    ]
		};
	    var waveHeight = echarts.init(document.getElementById('waveHeight'));
	    var currentspeed = echarts.init(document.getElementById('currentspeed'));
	    var waterlevel = echarts.init(document.getElementById('waterlevel'));
	    //var chartxz = echarts.init(document.getElementById('poseXZ'));
		$.ajax({
	   		url  : '',
			type : "POST",
			success : function(msg) {
				waveHeight.setOption(options);
				currentspeed.setOption(option3);
				waterlevel.setOption(options2);
				//chartxz.setOption(options);
			}
		});
		window.addEventListener('resize', function () {
			waveHeight.resize();
			currentspeed.resize();
			waterlevel.resize();
			//chartxz.resize();
        });
});

//页面加载  
/**$('#submit').click(function(){
	//var ylSelected = $('#ylSelector').combobox('getValues');
	var ylSelected = ['11','12'];
	var waveTran = $('#waveHeight').val();
	var speedTran = $('#currentspeed').val();
	
	var waveheight = $('#waveheight').combobox('getValue');
	var accelration = $('#accelration').combobox('getValue');
	var xyz1 = $('#xyz1').val();
	var chartWave = echarts.init(document.getElementById('waveHeight'));
	var chartCurrentspeed = echarts.init(document.getElementById('currentspeed'));

	var currentTime = new Date('2019-03-07 22:19:56.0');
	//页面显示时间
	var textTime=format('yyyy-MM-dd hh:mm:ss', currentTime);
	
	console.log(currentTime);
	$.ajax({
		url: 'pose/waveControl.do',
		type: 'get',
		data: {
			current: currentTime
		}

	}).done(function(data, status, xhr){
		//var obj = JSON.parse(data);
		let controlStartTime = null;
		let controlEndTime = null;
		let controlId = null;
		if (data != null) {
			controlStartTime = new Date(data.accelrationControlStime);
			controlEndTime = new Date(data.accelrationControlEtime);
			controlId = data.waveheightControlId;
		}
        
		
		$.ajax({
	   		url  : 'pose/getChartData.do',
			type : "POST",
			data : {
				start: currentTime,
				interval: 1,
				trans: waveTran,
				controlId: controlId
			},
			success : function(data) {
				//msg=JSON.parse(data);
				console.log(data.xdata);
				console.log(data.ydata);
				chartWave.setOption({
					fontFamily : 'Roboto',
					name : '流量 立方米/秒',
					backgroundColor : '#FFFFFF',
					title : {
						text : textTime,
						textStyle : {
							fontWeight : 'bolder',
							fontSize : 18,
							color : 'black',
						},
						right : '0%',
						top : '0%'
					},

					grid : {
						left : '1%',
						right : '5%',
						bottom : '0%',
						containLabel : true
					},
					xAxis : [ {
						type : 'category',
						boundaryGap : false,
						data : data.xdata,
						axisLabel : {
							show : true,
							interval : 0,
							//fontSize : 20,
							color : '#ffffff',
							fontWeight : 'bold',
							formatter : '{value}'
						},
						axisLine : {
							show : false
						},
						axisTick : {
							show : true
						},
					} ],
					yAxis : [ {
						show : true,
						max : 5,
					} ],
					series : [ {
						name : '波高',
						type : 'line',
						smooth : true,
						symbol : 'circle',
						showSymbol : true,
						lineStyle : {
							normal : {
								color : '#79CDCD',
								width : 3,
							}
						},

						label : {
							normal : {
								show : true,
								position : 'top',
								color : '#fff',
								fontSize : 24,
							},
						},
						
						data :data.ydata
					} ]
				});
			}
		});
		
		//resize
		window.addEventListener('resize', function () {
			chartWave.resize();
    });	
});
	//流速
	$.ajax({
		url: 'pose/currentSpeedControl.do',
		type: 'get',
		data: {
			current: currentTime
		}

	}).done(function(data, status, xhr){
		//var obj = JSON.parse(data);
		let controlStartTime = null;
		let controlEndTime = null;
		let controlId = null;
		if (data != null) {
			//controlStartTime = new Date(obj.accelrationControlStime);
			//controlEndTime = new Date(obj.accelrationControlEtime);
			controlId = data.currentspeedControlId;
		}
		
		$.ajax({
	   		url  : 'pose/getCurrentSpeedData.do',
			type : "POST",
			data : {
				start: currentTime,
				interval: 1,
				trans: speedTran,
				controlId: controlId
			},
			success : function(msg) {
				//msg=JSON.parse(data);
				console.log(msg.xsdata);
				console.log(msg.ysdata);
				window.addEventListener("resize", function () {
					chartCurrentspeed.resize();
                });
				chartCurrentspeed.setOption({
					fontFamily : 'Roboto',
					name : 'aa',
					backgroundColor : '#FFFFFF',
					title : {
						text : textTime,
						textStyle : {
							fontWeight : 'bolder',
							fontSize : 18,
							color : 'black',
						},
						right : '0%',
						top : '0%'
					},

				
					xAxis : [ {
						type : 'category',
						boundaryGap : false,
						data : msg.xsdata,
						axisLabel : {
							show : true,
							interval : 0,
							color : '#ffffff',
							fontWeight : 'bold',
							formatter : '{value}'
						},
						axisLine : {
							show : false
						},
						axisTick : {
							show : true
						},
					} ],
					yAxis : [ {
						show : true
					} ],
					series : [ {
						name : '流速',
						type : 'line',
						smooth : true,
						symbol : 'circle',
						showSymbol : true,
						lineStyle : {
							normal : {
								color : '#79CDCD',
								width : 3,
							}
						},

						label : {
							normal : {
								show : true,
								position : 'top',
								color : '#fff',
								fontSize : 24,
							},
						},
						data :msg.ysdata
					} ]
				});
			}
			
		});
		//resize
		window.addEventListener('resize', function () {
			chartCurrentspeed.resize();
	});
});
	
	

});

function format(fmt, date) {
	var o = {
		"M+": date.getMonth() + 1, //月份   
		"d+": date.getDate(), //日   
		"h+": date.getHours(), //小时   
		"m+": date.getMinutes(), //分   
		"s+": date.getSeconds(), //秒   
		"q+": Math.floor((date.getMonth() + 3) / 3), //季度   
		"S": date.getMilliseconds() //毫秒   
	};
	if (/(y+)/.test(fmt))
		fmt = fmt.replace(RegExp.$1, (date.getFullYear() + "").substr(4 - RegExp.$1.length));
	for (var k in o)
		if (new RegExp("(" + k + ")").test(fmt))
			fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
	return fmt;
}*/
